home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / comm2 / kms20src.lha / KMSAUX / receiver.c < prev    next >
C/C++ Source or Header  |  1994-04-25  |  3KB  |  136 lines

  1.  
  2. /*
  3.  * Debug Server KMSAUX:
  4.  */
  5.  
  6. #include "stdio.h"
  7. #include "string.h"
  8. #include "stdlib.h"
  9.  
  10. #include <clib/dos_protos.h>
  11. #include <clib/exec_protos.h>
  12. #include <clib/alib_protos.h>
  13.  
  14. #include "aux-debug.h"
  15.  
  16. BOOL debugmode = FALSE; /* extra output with TRUE  */
  17. FILE *op = NULL;        /* file save output option */
  18.  
  19. LONG main(LONG arc, STRPTR *argv)
  20.    {
  21.    struct MsgPort *port;
  22.    struct DebugMsg *msg;
  23.    LONG port_signal, break_signals, signals;
  24.    STRPTR ptr;
  25.  
  26.    /* open the port */
  27.   
  28.    port = CreatePort(AUXDEBUGPORT, 0);
  29.    if (!port)
  30.       printf("Error creating port \"%s\"\n", AUXDEBUGPORT);
  31.    else
  32.       printf("Created port \"%s\" successfully.\n", AUXDEBUGPORT);
  33.  
  34.    port_signal = 1 << port->mp_SigBit; /* server port */
  35.    
  36.    break_signals = SIGBREAKF_CTRL_F;  /* toggle file save option */
  37.    break_signals |= SIGBREAKF_CTRL_C;
  38.    break_signals |= SIGBREAKF_CTRL_D; /* turn on Debug info */
  39.    break_signals |= SIGBREAKF_CTRL_E; /* Exit */
  40.  
  41.    printf("\nCTRL-F: Toggle save | CTRL-D: Debug info | CTRL-E: Exit\n\n");
  42.  
  43.    /* process until a control-E to exit */
  44.  
  45.    while(TRUE)
  46.       {
  47.       signals = Wait(port_signal | break_signals);
  48.  
  49.       if (signals & port_signal) /* debug messages first */
  50.          {
  51.          while (msg = (struct DebugMsg *)GetMsg(port))
  52.             {
  53.             if (debugmode || msg->flag)
  54.                {
  55.                if (debugmode)
  56.                   {
  57.                   for(ptr = msg->msg; *ptr; ptr++)
  58.                      if (*ptr < 20 || *ptr > 126)
  59.                         *ptr = '.';
  60.  
  61.                   printf("%s %ld %ld %ld\n", msg->msg, msg->a, msg->b, msg->c);
  62.             
  63.                   if (op)
  64.                      fprintf(op, "%s %ld %ld %ld\n", msg->msg, msg->a, msg->b, msg->c);
  65.                   }
  66.                else
  67.                   {
  68.                   printf("%s", msg->msg);
  69.                   
  70.                   if (op)
  71.                      fprintf(op, "%s", msg->msg);
  72.                   }
  73.                }
  74.  
  75.             FreeMem(msg->msg, strlen(msg->msg) + 1);
  76.             FreeMem(msg, sizeof(struct DebugMsg));
  77.             }
  78.          }
  79.  
  80.       if (signals & SIGBREAKF_CTRL_D)
  81.          {
  82.          debugmode = !debugmode;
  83.       
  84.          printf("Got Control_D, debug is %s...\n", (debugmode) ? "on" : "off");
  85.       
  86.          if (op)
  87.             fprintf(op, "Got Control_D, debug is %s...\n", (debugmode) ? "on" : "off");
  88.          }
  89.  
  90.       if (signals & SIGBREAKF_CTRL_E)
  91.          {
  92.          printf("Got Control_E, exiting\n");
  93.          
  94.          break;
  95.          }
  96.  
  97.       if (signals & SIGBREAKF_CTRL_F)
  98.          {
  99.          printf("Got Control_F, File save option is turned ");
  100.  
  101.          if (op)
  102.             fprintf(op, "Got Control_F, File save option is turned off.\n");
  103.       
  104.          if (op == NULL)
  105.             {
  106.             printf("on...\n");
  107.             
  108.             op = fopen("T:save.aux", "a");
  109.             if (!op)
  110.                printf("Error: T:save.aux could not be opened!\n");
  111.             }
  112.          else /* already logging, turn it off */
  113.             {
  114.             printf("off...\n");
  115.  
  116.             fclose(op);
  117.             op = NULL;
  118.             }
  119.          }
  120.       }
  121.  
  122.    if (port)
  123.       {
  124.       Forbid();
  125.       while (msg = (struct DebugMsg *)GetMsg(port));
  126.       DeletePort(port); /* remove the server port */
  127.       Permit();
  128.       }
  129.  
  130.    if (op)
  131.       fclose(op);
  132.  
  133.    exit(0);
  134.    }
  135.  
  136.